#ifndef _Z80_THREAD_H_
#define _Z80_THREAD_H_

//by conleon1988@gmail.com based on ChillyWilly's Z80 music demo code

#define Z80_THREAD_IDLE(){Z80_requestBus(1); *((unsigned char *)0xA00042) = 0;Z80_releaseBus();}
#define Z80_THREAD_TIMING(){Z80_requestBus(1);*((unsigned char *)0xA00042) = 1;Z80_releaseBus();}
#define Z80_THREAD_RESULT(__RES__)\
{\
	Z80_requestBus(1);\
	__RES__ = (unsigned short)(*((unsigned char *)0xA00040)) | ((unsigned short)(*((unsigned char *)0xA00041)) << 8);\
	Z80_releaseBus();\
}

const unsigned char z80_thread[147] = {
    0xf3,0x31,0x00,0x20,0xed,0x56,0xc3,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xed,0x4d,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x21,0x00,0x00,0x22,0x40,0x00,0x3a,0x42,0x00,0xb7,0x28,0xf4,0x23,0x22,0x40,0x00,
    0xc3,0x86,0x00,
};
#endif // _Z80_THREAD_H_
